local sk__mowu = fk.CreateSkill {

  name = "sk__mowu",

  tags = {},

}



sk__mowu:addEffect(fk.CardUseFinished, {
  name = "sk__mowu",
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(sk__mowu.name) and (data.card.type == Card.TypeBasic or data.card:isCommonTrick()) and data.tos and
        not (data.extra_data and data.extra_data.sk__mowu) then
      if target == player then
        return table.find(data.tos, function(id)
          return id ~= player
        end)
      else
        return table.contains(data.tos, player)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, sk__mowu.name, nil, "#sk__mowu-invoke:::" .. data.card:toLogString())
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local draw_targets = table.simpleClone(data.tos)
    table.insert(draw_targets, target)
    room:sortByAction(draw_targets)
    for _, id in ipairs(draw_targets) do
      local p = id
      if not p.dead then
        p:drawCards(1, sk__mowu.name)
      end
    end
    if table.find(draw_targets, function(id)
          return not id.dead
        end) then
      data.extra_data = data.extra_data or {}
      data.extra_data.sk__mowu = true
      room:useCard(data)
    end
  end,
})

return sk__mowu
